package graphics;

import javax.swing.JPanel;
import javax.swing.JLabel;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

import java.util.Observable;
import java.util.Observer;

import model.Ressources;
import model.building.Building;

import java.util.*;

public class GActivity extends JPanel implements Observer {
	    
    /** Attributs */
    private Ressources m_economy;
    private GridBagConstraints m_gridBagConstraints;
	    
    /** Constructeurs */
    public GActivity(Building.Activity activity, Ressources economy) {
        super(new GridBagLayout());
        m_gridBagConstraints = new GridBagConstraints();
        m_gridBagConstraints.gridx = 0;
        m_gridBagConstraints.gridy = GridBagConstraints.RELATIVE;
        m_gridBagConstraints.insets = new Insets(5,10,5,10);
        activity.addObserver(this);

        m_economy = economy;
        update(activity,null);
    }

    /** Mutateurs */
    

    /** Methodes */
    public void update(Observable activity, Object activityUpdate) {
        Building.Activity a = (Building.Activity)activity;
        removeAll();
        
        Ressources r = a.getImpact(1.0, m_economy);
        for(Ressources.Type t : r.types()) add(new JLabel(t+" : "+r.getQuantity(t)), m_gridBagConstraints);

        repaint();
    }
}
